﻿$(function() {
    SentenceCreate.init();
    Utils.textBoxsOnEnter(SentenceCreate.Create);
});


var SentenceCreate =
{
    init: function() {
        $("#btnSave").click(this.Create);
        $("#Sentence").focus();
        $(document).keyup(function(e) {
            if (e.keyCode == 27) {
                var needConfirm = utility.hasFormData();
                window.parent.utility.closePopUpUrlConfirm(needConfirm);
            }
        });
    },
    Create: function() {
        var Sentence = $("#Sentence");
        var VoiceWord = $("#VoiceWord");
        var categorySn = $("#categorySn");

        targetFunction = (parent != undefined) ? parent.ErrorHelper : ErrorHelper;
        targetFunction.checkNonNull(Sentence, m.Err1101);
        targetFunction.checkNonNull(VoiceWord, m.Err1102);
        if (!targetFunction.popUpIfError()) {
            var param = {
                Sentence: Sentence.val()
                , VoiceWord: VoiceWord.val()
                , categorySn: categorySn.val()
            };
            var cb = Utils.getCBfunction('Sentence');
            var ecb = function() { $("#Sentence").focus(); };
            window.parent.utility.ajaxext("SentenceService/Create", param, "POST", cb, ecb);
        }
    }
};
